package com.cskaoyan.controller.wx_goods;

import com.cskaoyan.bean.BaseParam;
import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.PageDataVo;
import com.cskaoyan.bean.wx_goods.WxGoodsDetailVO;
import com.cskaoyan.bean.wx_goods.WxGoodsCategoryVO;
import com.cskaoyan.bean.wx_goods.WxGoodsListPageVO;
import com.cskaoyan.service.wx_goods.WxGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @description: 前台的商品模块
 * @author: enhui
 **/
@RestController
@RequestMapping("wx/goods")
public class WxGoodsController {
    @Autowired
    WxGoodsService wxGoodsService;

    @RequestMapping("count")
    public BaseRespVo goodsCount() {
        int count = wxGoodsService.goodsCount();
        return BaseRespVo.ok(count);
    }

    @RequestMapping("category")
    public BaseRespVo getGoodsByCategory(Integer id) {
        WxGoodsCategoryVO categories = wxGoodsService.getGoodsByCategory(id);
        return BaseRespVo.ok(categories);
    }

    @RequestMapping("list")
    public BaseRespVo goodsList(String keyword, Integer brandId, Integer categoryId, BaseParam param) {
        WxGoodsListPageVO goodsList = wxGoodsService.goodsList(keyword, brandId, categoryId, param);
        return BaseRespVo.ok(goodsList);
    }

    @RequestMapping("detail")
    public BaseRespVo goodsDetail(Integer id, HttpServletRequest httpServletRequest) {
        WxGoodsDetailVO wxGoodsDetailVO = wxGoodsService.goodsDetail(id, httpServletRequest);//需要用这个request来获取ip
        return BaseRespVo.ok(wxGoodsDetailVO);
    }

    @RequestMapping("related")
    public BaseRespVo goodsRelated(Integer id) {
        PageDataVo goodsRelated = wxGoodsService.goodsRelated(id);
        return BaseRespVo.ok(goodsRelated);
    }
}
